# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>
# Contributor: Ian Beringer <ian@ianberinger.com>

pkgname=usbguard
pkgver=1.1.2
pkgrel=6
pkgdesc='Software framework for implementing USB device authorization policies'
url='https://github.com/USBGuard/usbguard'
arch=('loong64' 'x86_64')
license=('GPL2')
depends=('glibc' 'libqb' 'libqb.so' 'libsodium' 'libcap-ng' 'protobuf' 'polkit' 'dbus-glib'
         'audit' 'libaudit.so' 'libseccomp' 'libseccomp.so' 'libcap-ng.so' 'libgio-2.0.so'
         'libglib-2.0.so' 'libprotobuf.so')
makedepends=('catch2' 'pegtl' 'libxslt' 'libxml2' 'asciidoc' 'systemd')
provides=('libusbguard.so')
backup=(etc/usbguard/usbguard-daemon.conf
        etc/usbguard/rules.conf)
source=(https://github.com/USBGuard/usbguard/releases/download/usbguard-${pkgver}/usbguard-${pkgver}.tar.gz{,.asc}
        22b1e089.patch)
sha512sums=('03b6dd026a0fe6a7a055208f09a56e2cc86985570388e33fde08671b8aa2d60ea4a0e59505e9646ddf50f42f5b6310d1b230379f9c26ec99c7ca736f3b4ad850'
            'SKIP'
            'a544cf8787cd58e85d5acd78b0fcc88005e67b13f92947805561e3ec3b5de8518e109ab8e4aa91ce63f74b03b2d4be16e6a6ce4113865b3b94d9ca9204c369b1')
validpgpkeys=(
  'DE78B93EAED8A620F5AA14DF52F7E84653274B59' # Radovan Sroka <rsroka@redhat.com>
)

prepare() {
  cd ${pkgname}-${pkgver}
  autoreconf -fiv

# Fix build with GCC 12
  patch -p1 -i ../22b1e089.patch
}

build() {
  cd ${pkgname}-${pkgver}
  ./configure \
    --prefix=/usr \
    --sysconfdir=/etc \
    --localstatedir=/var \
    --sys=/etc \
    --sbindir=/usr/bin \
    --libdir=/usr/lib \
    --enable-systemd \
    --without-bundled-catch \
    --without-bundled-pegtl \
    --with-dbus \
    --with-polkit \
    --with-crypto-library=sodium
  make
  touch rules.conf
}

check() {
  cd ${pkgname}-${pkgver}
  make check
}

package() {
  cd ${pkgname}-${pkgver}
  make INSTALL='install -p' DESTDIR="${pkgdir}" install

  chmod 750 "${pkgdir}/etc/usbguard"
  install -Dpm 600 usbguard-daemon.conf rules.conf -t "${pkgdir}/etc/usbguard"

  install -Dpm 644 scripts/bash_completion/usbguard -t "${pkgdir}/usr/share/bash-completion/completions"
  install -Dpm 644 scripts/usbguard-zsh-completion "${pkgdir}/usr/share/zsh/site-functions/_usbguard"

  install -Dm 644 CHANGELOG.md README.adoc -t "${pkgdir}/usr/share/doc/${pkgname}"
}

# vim: ts=2 sw=2 et:
